package com.oa.system.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.oa.admin.entity.LeaveApply;
import com.oa.admin.entity.OutApply;
import com.oa.admin.entity.OutApplyPersonnel;
import com.oa.admin.entity.UserHoliday;
import com.oa.admin.service.ILeaveApplyService;
import com.oa.admin.service.IOutApplyPersonnelService;
import com.oa.admin.service.IOutApplyService;
import com.oa.admin.service.IUserHolidayService;
import com.oa.core.model.AttendanceMachineXls;
import com.oa.core.utils.DateUtil;
import com.oa.core.utils.ExcelUtil;
import com.oa.core.utils.SendMsgManager;
import com.oa.pm.entity.AttendanceReport;
import com.oa.pm.entity.Registration;
import com.oa.pm.mapper.AttendanceDetailsMapper;
import com.oa.pm.service.IAttendanceReportService;
import com.oa.pm.service.IRegistrationService;
import com.oa.pm.entity.AttendanceDetails;
import com.oa.pm.vo.AttendanceDetailsListVO;
import com.oa.system.entity.User;
import com.oa.system.service.IApplyApprovalService;
import com.oa.system.service.IAttendanceDetailsService;
import com.oa.system.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Array;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class AttendanceDetailsServiceImpl extends ServiceImpl<AttendanceDetailsMapper, AttendanceDetails> implements IAttendanceDetailsService {

    @Autowired
    private IRegistrationService registrationService;

    @Autowired
    private IUserService userService;

    @Autowired
    private IOutApplyService outApplyService;

    @Autowired
    private ILeaveApplyService leaveApplyService;

    @Autowired
    private IAttendanceReportService attendanceReportService;

    @Autowired
    private SendMsgManager sendMsgManager;

    @Autowired
    private IUserHolidayService userHolidayService;

    @Autowired
    private IApplyApprovalService applyApprovalService;

    @Autowired
    private IOutApplyPersonnelService outApplyPersonnelService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void importReport(List<AttendanceMachineXls> attendanceMachineXls, String beginTime, String endTime, String userId, String fileName){
        AttendanceReport attendanceReport = new AttendanceReport();
        attendanceReport.setReportName(fileName);
        attendanceReport.setStatus(1);
        attendanceReport.setUserId(userId);
        attendanceReport.setCreateTime(new Date());
        attendanceReportService.insert(attendanceReport);

//        Thread sayHello = new Thread(() -> {
//            statistics(attendanceMachineXls, beginTime, endTime, attendanceReport.getId(), userId);
//        });
//        sayHello.start();
        statistics(attendanceMachineXls, beginTime, endTime, attendanceReport.getId(), userId);
    }


    @Override
    public void export(Long id, HttpServletResponse response) throws Exception {
        List<AttendanceDetails> attendanceDetails = selectList(new EntityWrapper().eq("attendance_report_id", id));
        List<AttendanceDetailsListVO> attendanceDetailsListVOS = new ArrayList<>();
        attendanceDetails.forEach(d -> {
            AttendanceDetailsListVO attendanceDetailsListVO = new AttendanceDetailsListVO();
            BeanUtils.copyProperties(d, attendanceDetailsListVO);
            attendanceDetailsListVOS.add(attendanceDetailsListVO);
        });
        String[] rows = {"考勤编号", "用户名称", "部门", "迟到分钟", "迟到次数", "早退分钟", "早退次数", "旷工分钟", "旷工次数", "事假", "病假", "调休", "年假", "婚假", "产假", "陪产假", "丧假", "青年节假", "妇女节假", "延后假", "外出天数", "出差天数", "办公室天数", "剩余年休假", "剩余调休假", "剩余产假", "剩余陪产假", "剩余延后假"};
        ExcelUtil.downloadExcel("考勤列表详情" + DateUtil.getDayMonth(), rows, attendanceDetailsListVOS, "考勤列表详情" + DateUtil.getDayMonth()+".xls", response);
    }

    @Transactional(rollbackFor = Exception.class)
    public void statistics(List<AttendanceMachineXls> attendanceMachineXls, String beginTime, String endTime, Long id, String masterId){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:dd");

        List<AttendanceDetails> attendanceDetailsList = new ArrayList<>();

        List<User> users = userService.selectList(new EntityWrapper().eq("is_deleted", 2));
        List<String> names = new ArrayList<>();
        users.forEach(d -> names.add(d.getName()));

        names.forEach(name -> {
            List<AttendanceMachineXls> attendanceMachineXlsHandle = attendanceMachineXls.stream().filter(w -> Objects.equals(name, w.getName())).collect(Collectors.toList());
            for(int i = 0; i < attendanceMachineXlsHandle.size(); i++){
                for(int j = 0; j < attendanceMachineXlsHandle.size(); j++){
                    if(attendanceMachineXlsHandle.get(i).getDate().equals(attendanceMachineXlsHandle.get(j).getDate())){
                        List<String> list = new ArrayList<>();
                        List<String> list1 = Arrays.asList(attendanceMachineXlsHandle.get(i).getTimes().split(" "));
                        List<String> list2 = Arrays.asList(attendanceMachineXlsHandle.get(j).getTimes().split(" "));
                        list.addAll(list1);
                        list.addAll(list2);
                        Set<String> set1 = new LinkedHashSet<>();
                        set1.addAll(list);
                        list.clear();
                        list.addAll(set1);
                        list.sort(((o1, o2) -> {
                            try {
                                if(StringUtils.isNotBlank(o1) && StringUtils.isNotBlank(o2)){
                                    long o1time = sdf.parse("1970-01-01 " + o1 + ":00").getTime();
                                    long o2time = sdf.parse("1970-01-01 " + o2 + ":00").getTime();
                                    return Integer.valueOf(String.valueOf(o1time - o2time));
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            return 0;

                        }));
                        attendanceMachineXlsHandle.get(i).setTimes(StringUtils.join(list.toArray(), " ").trim());
                    }
                }
            }
            attendanceMachineXlsHandle = attendanceMachineXlsHandle.stream().collect(
                    Collectors.collectingAndThen(
                            Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(AttendanceMachineXls::getDate))), ArrayList::new));

            AttendanceDetails attendanceDetails = new AttendanceDetails();
            attendanceDetails.setName(name);
            attendanceDetails.setAttendanceReportId(id);

            User user = userService.selectOne(new EntityWrapper<User>().eq("name", name));

            if(user != null) {

                String userId = user.getId();
                attendanceMachineXlsHandle.forEach(w -> {
                    attendanceDetails.setDepartment(w.getDepartment());
                    attendanceDetails.setAttendanceNumber(w.getAttendance());
                    w.setDate(w.getDate().replace("/", "-"));

                    try{
                        boolean weekendBoo  =weekendHander(w.getDate()+" 12:00:00");
                        System.out.println(w.getDate()+" 12:00:00 ---" + weekendBoo);
                        if(weekendBoo){
                            return;
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                    if (StringUtils.isNotBlank(w.getTimes())) {
                        String outApplySql = "user_id = {0} and out_apply_id = (\n" +
                                "\tselect a.id\n" +
                                "\tfrom admin_out_apply as a \n" +
                                "\tinner join sys_apply_approval as b on a.id = b.apply_id\n" +
                                "\twhere b.approval_node_id = 0 and a.start_time <= {1} and a.end_time >= {1} \n" +
                                ")\n" +
                                "\n";

                        Map<String, String> toDayTime = timesHander(w.getTimes());

                        Integer checkInHour = timeToInt(toDayTime.get("checkIn").split(":")[0]);
                        Integer checkInMinute = timeToInt(toDayTime.get("checkIn").split(":")[1]);

                        String checkInDateStr = w.getDate() + " " + toDayTime.get("checkIn") + ":00";

                        if (registrationService.checkInHander(checkInHour, checkInMinute) > 1) {

                            Date checkIn = null;
                            Integer mins = null;
                            try {
                                checkIn = sdf.parse(checkInDateStr);
                                mins = registrationService.minuteDifference(checkIn, sdf.parse(w.getDate() + " 08:30:00"));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                            Integer outApplyCount = outApplyPersonnelService.selectCount(new EntityWrapper().where(outApplySql, userId, checkInDateStr));

                            if(mins > 0){
                                // 计算旷工时长 1旷工 2正常
                                if(registrationService.completionHander(checkInHour, checkInMinute) == 1 && outApplyCount == 0){
                                    try {
                                        if(handerApply(sdf.parse(w.getDate() + " " + toDayTime.get("checkIn") + ":00"), userId) == 0){
                                            attendanceDetails.setAbsenteeismCount(attendanceDetails.getAbsenteeismCount() == null ? 1 : attendanceDetails.getAbsenteeismCount() + 1);
                                            attendanceDetails.setAbsenteeismMinute(attendanceDetails.getAbsenteeismMinute() == null ? 8 : attendanceDetails.getAbsenteeismMinute() + 8);
                                        }
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                    }
                                }else{
                                    //迟到分钟
                                    attendanceDetails.setBeLateMinute(attendanceDetails.getBeLateMinute() == null ? mins : attendanceDetails.getBeLateMinute() + mins);
                                    attendanceDetails.setBeLateCount(attendanceDetails.getBeLateCount() == null ? 1 : attendanceDetails.getBeLateCount() + 1);
                                }
                            }
                        }

                        Integer signOffHour = timeToInt(toDayTime.get("signOff").split(":")[0]);
                        Integer signOffMinute = timeToInt(toDayTime.get("signOff").split(":")[1]);

                        if (registrationService.signOffHander(signOffHour, signOffMinute) == 3) {

                            Date signOff = null;
                            Integer mins = null;
                            try {
                                signOff = sdf.parse(w.getDate() + " " + toDayTime.get("signOff") + ":00");
                                mins =  registrationService.minuteDifference(sdf.parse(w.getDate() + " 17:30:00"), signOff);
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                            Integer outApplyCount = outApplyPersonnelService.selectCount(new EntityWrapper().where(outApplySql, userId, checkInDateStr));

                            if(mins > 0 && outApplyCount == 0){
                                attendanceDetails.setLeaveEarlyMinute(attendanceDetails.getLeaveEarlyMinute() == null ? mins : attendanceDetails.getLeaveEarlyMinute() + mins);
                                attendanceDetails.setLeaveEarlyCount(attendanceDetails.getLeaveEarlyCount() == null ? 1 : attendanceDetails.getLeaveEarlyCount() + 1);
                            }
                        }else if(registrationService.signOffHander(signOffHour, signOffMinute) == 2){
                            Integer outApplyCount = outApplyPersonnelService.selectCount(new EntityWrapper().where(outApplySql, userId, w.getDate()));
                            try {
                                if(handerApply(sdf.parse(w.getDate() + " " + "00:00:00"), userId) == 0 && outApplyCount == 0){
                                    attendanceDetails.setAbsenteeismCount(attendanceDetails.getAbsenteeismCount() == null ? 1 : attendanceDetails.getAbsenteeismCount() + 1);
                                    attendanceDetails.setAbsenteeismMinute(attendanceDetails.getAbsenteeismMinute() == null ? 8 : attendanceDetails.getAbsenteeismMinute() + 8);
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                        }

                    } else {
                        String outApplySql = "user_id = {0} and out_apply_id = (\n" +
                                "\tselect a.id\n" +
                                "\tfrom admin_out_apply as a \n" +
                                "\tinner join sys_apply_approval as b on a.id = b.apply_id\n" +
                                "\twhere b.approval_node_id = 0 and DATE_FORMAT(a.start_time, '%Y-%c-%e') <= {1} and DATE_FORMAT(a.end_time, '%Y-%c-%e') >= {1} \n" +
                                ")\n" +
                                "\n";

                        Integer outApplyCount = outApplyPersonnelService.selectCount(new EntityWrapper().where(outApplySql, userId, w.getDate()));
                        try {
                            if(handerApply(sdf.parse(w.getDate() + " " + "00:00:00"), userId) == 0 && outApplyCount == 0){
                                attendanceDetails.setAbsenteeismCount(attendanceDetails.getAbsenteeismCount() == null ? 1 : attendanceDetails.getAbsenteeismCount() + 1);
                                attendanceDetails.setAbsenteeismMinute(attendanceDetails.getAbsenteeismMinute() == null ? 8 : attendanceDetails.getAbsenteeismMinute() + 8);
                            }
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }

                    }
                });

                //事假
                List<LeaveApply> leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 2)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );
                double day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setThingLeaveCount(day);

                //病假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 3)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setSickLeaveCount(day);

                //调休
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 4)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setChangeCount(day);

                //年假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 1)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setAnnualLeaveCount(day);

                //婚假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 7)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setMarriageLeaveCount(day);

                //产假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 5)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setMaternityLeaveCount(day);

                //陪产假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 6)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setPaternityLeaveCount(day);

                //丧假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 9)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setFuneralLeaveCount(day);

                //青年节
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 18)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setYouthHolidayLeaveCount(day);

                //妇女节
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 17)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }
                attendanceDetails.setWomenHolidayLeaveCount(day);

                //延后假
                leaveApplys = leaveApplyService.selectList(
                        new EntityWrapper<LeaveApply>()
                                .eq("user_id", userId)
                                .eq("leave_type", 19)
                                .ge("leave_start_time", beginTime)
                                .le("leave_end_time", endTime)
                                .eq("status", 2)
                );

                day = 0;
                if (leaveApplys != null && leaveApplys.size() > 0) {
                    for (LeaveApply d : leaveApplys) {
                        day += leaveApplyService.calculationDay(d.getLeaveStartTime(), d.getLeaveEndTime());
                    }
                }

                attendanceDetails.setDelayedLeaveCount(day);

                List<OutApply> outApplys = outApplyService.selectList(new EntityWrapper<OutApply>()
                        .where("id in (select out_apply_id from admin_out_apply_personnel where user_id = {0}) and start_time >= {1} and end_time <= {2} and type = {3}",
                                userId,
                                beginTime,
                                endTime,
                                1
                        )
                );
                day = 0;
                for (OutApply o : outApplys) {
                    day += leaveApplyService.calculationDay(o.getStartTime(), o.getEndTime());
                }

                attendanceDetails.setGoOutCount(day);

                outApplys = outApplyService.selectList(new EntityWrapper<OutApply>()
                        .where("id in (select out_apply_id from admin_out_apply_personnel where user_id = {0}) and start_time >= {1} and end_time <= {2} and type = {3}",
                                userId,
                                beginTime,
                                endTime,
                                2
                        )
                );

                day = 0;
                for (OutApply o : outApplys) {
                    day += leaveApplyService.calculationDay(o.getStartTime(), o.getEndTime());
                }
                attendanceDetails.setBusinessTripCount(day);

                Integer registrationsCount = registrationService.selectCount(
                        new EntityWrapper<Registration>()
                                .ge("registration_date", beginTime)
                                .le("registration_date", endTime)
                                .eq("user_id", userId)
                                .eq("status", 1)
                                .eq("status", 2)
                                .eq("status", 3)
                                .eq("form", 1)
                );
                attendanceDetails.setOfficeDayCount(registrationsCount * 0.5);


                attendanceDetailsList.add(attendanceDetails);

                UserHoliday userHoliday = userHolidayService.selectOne(new EntityWrapper().where("user_id = {0} and holiday_id = {1}", user.getId(), 1));
                if(userHoliday != null){
                    attendanceDetails.setRemainingAnnualLeave(userHoliday.getSurplusDay());
                }

                userHoliday = userHolidayService.selectOne(new EntityWrapper().where("user_id = {0} and holiday_id = {1}", user.getId(), 4));
                if(userHoliday != null){
                    attendanceDetails.setRemainingAdjustmentLeave(userHoliday.getSurplusDay());
                }

                userHoliday = userHolidayService.selectOne(new EntityWrapper().where("user_id = {0} and holiday_id = {1}", user.getId(), 5));
                if(userHoliday != null){
                    attendanceDetails.setRemainingMaternityLeave(userHoliday.getSurplusDay());
                }

                userHoliday = userHolidayService.selectOne(new EntityWrapper().where("user_id = {0} and holiday_id = {1}", user.getId(), 6));
                if(userHoliday != null){
                    attendanceDetails.setRemainingPaternityLeave(userHoliday.getSurplusDay());
                }

                userHoliday = userHolidayService.selectOne(new EntityWrapper().where("user_id = {0} and holiday_id = {1}", user.getId(), 19));
                if(userHoliday != null){
                    attendanceDetails.setRemainingDelayedLeave(userHoliday.getSurplusDay());
                }
            }

        });

        User user = userService.selectById(masterId);
        if(attendanceDetailsList != null && attendanceDetailsList.size() > 0){
            if(insertBatch(attendanceDetailsList)){
                sendMsgManager.sendMsg(user, "考勤报表", "数据已经收集完成");
                AttendanceReport attendanceReport = new AttendanceReport();
                attendanceReport.setId(id);
                attendanceReport.setStatus(2);
                attendanceReportService.updateById(attendanceReport);
            }
        }else{
            attendanceReportService.deleteById(id);
            sendMsgManager.sendMsg(user, "考勤报表", "数据收集失败");
            return;
        }
    }

    Integer handerApply(Date beginTime, String userId){
        Integer num =  leaveApplyService.selectCount(
                new EntityWrapper<LeaveApply>()
                        .eq("user_id", userId)
                        .ge("leave_start_time", beginTime)
                        .le("leave_end_time", beginTime)
                        .eq("status", 2)
        );

        num +=  outApplyService.selectCount(
                new EntityWrapper<OutApply>()
                    .eq("start_time", beginTime)
                    .eq("end_time", beginTime)
                    .eq("proposer", userId)
        );
        return num;
    }


    Integer timeToInt(String time){
        if(time.equals("00")){
            return 0;
        }
        if(time.charAt(0) == '0'){
            return Integer.valueOf(time.replace("0", ""));
        }
        return Integer.valueOf(time);
    }

    Map<String, String> timesHander(String times){
        String[] timeArr = times.split(" ");
        Map map = new HashMap();
        map.put("checkIn", timeArr[0]);
        map.put("signOff", timeArr[timeArr.length - 1]);
        return map;
    }

    boolean weekendHander(String bDate) throws ParseException {

        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        Date bdate = format1.parse(bDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(bdate);
        if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
            return true;
        } else{
            return false;
        }
    }
}
